<template>
  <div class="goods-outstock">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>商品出库</span>
      </div>
      <div class="text item">
        <el-form
          size="small"
          :model="goodsOutStockForm"
          status-icon
          :rules="rules"
          ref="goodsOutStockForm"
          label-width="100px"
          class="demo-ruleForm"
          hide-required-asterisk
        >
          <el-form-item label="商品ID" prop="gId">
            <el-input
              type="text"
              v-model="goodsOutStockForm.gId"
              autocomplete="off"
              style="width: 200px"
            ></el-input>
          </el-form-item>
          <el-form-item label="数量" prop="num">
            <el-input type="text" v-model="goodsOutStockForm.num" autocomplete="off" style="width: 200px"></el-input>
            <span style="height:16px;line-height:16px;font-size:12px;color:#aaa"> 计重商品单位为千克</span>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm()">加入订单</el-button>
            <el-button @click="resetForm('goodsOutStockForm')">重新出库</el-button>
          </el-form-item>

            <el-table
            ref="multipleTable"
            :data="tableData"
            tooltip-effect="dark"
            style="width: 100%"
            stripe
            @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection"></el-table-column>
                <el-table-column prop="gName" label="商品名称"></el-table-column>
                <el-table-column prop="saleNum" label="数量"></el-table-column>
                <el-table-column prop="singlePrice" label="单价(元)"></el-table-column>
                <el-table-column prop="totalPrice" label="总价(元)"></el-table-column>
                <!--<el-table-column prop="discountTotalPrice" label="优惠总价(元)"></el-table-column>-->
            </el-table>

          <!--<el-form-item label="会员卡号">-->
            <!--<el-input-->
              <!--type="text"-->
              <!--v-model="goodsOutStockForm.membershipNum"-->
              <!--autocomplete="off"-->
              <!--style="width: 300px"-->
              <!--placeholder="填写会员卡号"-->
            <!--&gt;</el-input>-->
          <!--</el-form-item>-->
          <el-form-item>
            <el-button type="primary" @click="submit">确认提交</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      goodsOutStockForm: {
          gId: "",
        num: "",
        membershipNum:""
      },
      rules: {
        gId: [
          { required: true, message: "ID不能为空", trigger: "blur" }
        ],
        num: [{ required: true, message: "数量不能为空", trigger: "blur" }]
      },
      tableData: [
      ]
    };
  },
  methods: {
      submitForm() {
          this.$axios
              .get("/goods/queryId",
                  { params:{
                          gId:this.goodsOutStockForm.gId
                      }
                  }
              )
              .then(response => {
                  console.log(response.data.gName);

                  this.tableData.push(({
                      gId:response.data.gId,
                      gName: response.data.gName,
                      saleNum: this.goodsOutStockForm.num,
                      singlePrice: response.data.salePrice,
                      totalPrice: parseFloat(this.goodsOutStockForm.num)*parseFloat(response.data.salePrice),
                      // discountTotalPrice:"15.00"
                  }))
              })




    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    submit (){
          this.$axios
              .post("/orderDetail/insertBatch",
                  this.tableData)
              .then(response => {
                  console.log("成功");
                  this.$router.push("/index");
              })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  }
};
</script>
<style lang="less">
.goods-outstock {
  .el-card {
      .el-card__header {
      font-size: 20px;
      font-weight: 600;
      background-color: #f1f1f1;
    }
    .el-card__body {
      .el-form{
          .el-table {
            margin-bottom: 20px;
          }
      }
    }
  }
}
</style>